var loginObj = {
    el: '#pageApp',
    data: {
      editNickName:false,
      nickName:'',
        headerImg:'',
      inputVal:'',
      hasGetCode:false,
      countTimer:null,
      countTimeNum:59,
      tel:'',
      code:'',
      getCodeTel:'',
      sendCode:'',
    },
    components:{

    },
    methods: {
      showNickNameModal:function(){
        this.editNickName = true;
      },
      hideNickNameModal:function(){
        this.editNickName = false;
      },
      submitNickName:function(){
        this.nickName = this.inputVal;
        this.hideNickNameModal();
      },
      getCode:function(){
         if(!g.validate.mobile(this.tel)){
            g.modal.tip({title:'请输入正确的手机号码！'});
            return;
         }
         this.hasGetCode = true;
         this.countGetCodeTime();
         this.getCodeTel = this.tel;
         this.sendCode = Math.random().toFixed(4).substring(2);
         var _this = this;
         g.ajax({
           type: 'GET',
           url: g.url.format('/api/user/sendTsCode'),
           data:{ phone:_this.tel,code:_this.sendCode},
           success: function (result) {

           }
         });
      },
      countGetCodeTime:function(){
         this.countTimer = setInterval(function(){
           this.countTimeNum--;
           if(this.countTimeNum == 0){
             clearInterval(this.countTimer);
             this.hasGetCode= false;
             this.countTimeNum = 59;
           }
         }.bind(this),1000)
      },
      login:function(){
        // if(this.tel != this.getCodeTel){
        //   g.modal.tip({title:'手机号码不正确！'});
        //   return;
        // };
        // if(this.code != this.sendCode){
        //   g.modal.tip({title:'验证码不正确！'});
        //   return;
        // };
        this.bindingWechat();
      },
      bindingWechat:function(){
        var _this = this;
        g.ajax({
          type: 'POST',
          url: g.url.format('/api/user/bindingwechat'),
          data:{
             phone:_this.tel,
             code:123456,
              openId:_this.openId,
             img:_this.headerImg ,
             userName:_this.tel,
             nickName:_this.nickName,
          },
          success: function (result) {
              g.storage.setToken(result.data.token);
              debugger;
              g.window.openNew(g.url.urlHref('/page/index.html'));
          }
        });
      }

    },
    mounted:function () {
        this.headerImg = g.params.get("headerimg");
        this.openId =  g.params.get("openid");
      this.nickName =decodeURIComponent(g.params.get("nickname"));
      this.inputVal = this.nickName;
    }
};
var initPage = function(){
  new Vue(loginObj);
};

